/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.view.gui;

import app.entities.MOCK.MockPersistencia;
import app.entities.model.DTO.AlunoDTO;
import app.entities.model.DTO.MatriculaAlunoDTO;
import app.entities.model.DTO.MatriculaProfessorDTO;
import app.entities.model.DTO.ProfessorDTO;
import app.entities.model.DTO.TurmaDTO;
import app.view.classes.ViewAluno;
import app.view.classes.ViewProfessor;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 *
 * @author Murilo
 */
public class PrincipalSelecaoUsuario extends javax.swing.JFrame {

    String seta_look = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    private ViewProfessor viewProf;
    private ViewAluno viewAluno;

    /**
     * Creates new form PrincipalSelecaoUsuario
     */
    public PrincipalSelecaoUsuario() {
        initComponents();
        
        // Centraliza:
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        pack();
        setLocation((screenSize.width/2) - (getWidth()/2), (screenSize.height/2) - (getHeight()/2));
        
        
        this.viewProf = new ViewProfessor();
        this.viewAluno = new ViewAluno();
        PopulaMock();
        LookAndFeel();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema Acadêmico - Seleção de Usuário");
        setForeground(java.awt.Color.lightGray);
        setMinimumSize(new java.awt.Dimension(200, 200));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Seleção Usuário"));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/app/view/gui/imgs/10680_64x64.png"))); // NOI18N
        jButton1.setText("Professor");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/app/view/gui/imgs/7741_64x64.png"))); // NOI18N
        jButton2.setText("Aluno");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/app/view/gui/imgs/adm.png"))); // NOI18N
        jButton3.setText("Administrador");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jButton3)
                .addGap(2, 2, 2)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton3)
                .addComponent(jButton1)
                .addComponent(jButton2))
        );

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/app/view/gui/imgs/images (2).jpg"))); // NOI18N
        jButton4.setText("Sair");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(209, 209, 209)
                .addComponent(jButton4)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        this.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        String Codigomatricula = null;
        while (Codigomatricula == null || Codigomatricula.equals("")) {
            Codigomatricula = JOptionPane.showInputDialog("Digite seu Código de Matrícula.");
            if (Codigomatricula == null || Codigomatricula.equals("")) {
                JOptionPane.showMessageDialog(null, "Por Favor Digite um Código.");
            } else {
                if (this.viewAluno.verificarMatriculaAluno(Codigomatricula)) {
                    PrincipalAluno PA = new PrincipalAluno(Codigomatricula);
                    PA.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Código de Matrícula inválido.");
                }
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            PrincipalAdm PAD = new PrincipalAdm();
            PAD.setVisible(true);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PrincipalSelecaoUsuario.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String Codigomatricula = null;
        while (Codigomatricula == null || Codigomatricula.equals("")) {
            Codigomatricula = JOptionPane.showInputDialog("Digite seu Código de Matrícula.");
            if (Codigomatricula == null || Codigomatricula.equals("")) {
                JOptionPane.showMessageDialog(null, "Por Favor Digite um Código.");
            } else {
                if (this.viewProf.verificarMatriculaProfessor(Codigomatricula)) {
                    PrincipalProfessor PF = new PrincipalProfessor(Codigomatricula);
                    PF.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Código de Matrícula inválido.");
                }
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PrincipalSelecaoUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PrincipalSelecaoUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PrincipalSelecaoUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PrincipalSelecaoUsuario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PrincipalSelecaoUsuario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

    public void LookAndFeel() {
        try {
            UIManager.setLookAndFeel(seta_look);
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro ao alterar o tema " + ex.getMessage());
        }
    }

    public void PopulaMock() {

        //Adiociona os professores e matricula os professores
        ArrayList<ProfessorDTO> ListProfessores = new ArrayList<>();
        ProfessorDTO prof1 = new ProfessorDTO(1, "Murilo", "Camargo", new Date());
        ProfessorDTO prof2 = new ProfessorDTO(2, "João", "Das Couves", new Date());
        ProfessorDTO prof3 = new ProfessorDTO(3, "Maria", "Juventina", new Date());
        ProfessorDTO prof4 = new ProfessorDTO(4, "Helena", "Borges", new Date());
        ProfessorDTO prof5 = new ProfessorDTO(5, "Isabela", "Campos", new Date());
        ProfessorDTO prof6 = new ProfessorDTO(6, "Pedro", "Prestes", new Date());
        ListProfessores.add(prof3); ListProfessores.add(prof1); ListProfessores.add(prof2);
        ListProfessores.add(prof4); ListProfessores.add(prof5); ListProfessores.add(prof6);
        for (ProfessorDTO prof : ListProfessores) {
            MockPersistencia.getInstanciaListaProfessores().add(prof);
        }

        ArrayList<MatriculaProfessorDTO> ListaMatriculaProfessor = new ArrayList<>();
        MatriculaProfessorDTO matProf1 = new MatriculaProfessorDTO(prof1, 1, "codigo1", new Date(), true);
        MatriculaProfessorDTO matProf2 = new MatriculaProfessorDTO(prof2, 2, "codigo2", new Date(), true);
        MatriculaProfessorDTO matProf3 = new MatriculaProfessorDTO(prof3, 3, "codigo3", new Date(), true);
        MatriculaProfessorDTO matProf4 = new MatriculaProfessorDTO(prof4, 4, "codigo4", new Date(), true);
        MatriculaProfessorDTO matProf5 = new MatriculaProfessorDTO(prof5, 5, "codigo5", new Date(), true);
        MatriculaProfessorDTO matProf6 = new MatriculaProfessorDTO(prof6, 6, "codigo6", new Date(), true);
        ListaMatriculaProfessor.add(matProf1);
        ListaMatriculaProfessor.add(matProf2);
        ListaMatriculaProfessor.add(matProf3);
        ListaMatriculaProfessor.add(matProf4);
        ListaMatriculaProfessor.add(matProf5);
        ListaMatriculaProfessor.add(matProf6);
        for (MatriculaProfessorDTO matProf : ListaMatriculaProfessor) {
            MockPersistencia.getInstanciaListaMatriculaProfessores().add(matProf);
        }

        ArrayList<AlunoDTO> ListaAlunos = new ArrayList<>();
        AlunoDTO alun1 = new AlunoDTO(1, "Wilson", "Simonal", new Date());
        AlunoDTO alun2 = new AlunoDTO(2, "Frank", "Sinatra", new Date());
        AlunoDTO alun3 = new AlunoDTO(3, "Sidinho", "Das Mulheres", new Date());
        AlunoDTO alun4 = new AlunoDTO(4, "Fabricio", "Prestes", new Date());
        AlunoDTO alun5 = new AlunoDTO(5, "Emerson", "Sheik", new Date());
        AlunoDTO alun6 = new AlunoDTO(6, "Zidanilo", "Zidane", new Date());
        AlunoDTO alun7 = new AlunoDTO(7, "Romarino", "Por que faz isso", new Date());
        AlunoDTO alun10 = new AlunoDTO(8, "Paolo", "Guerrero", new Date());
        AlunoDTO alun11 = new AlunoDTO(9, "Ralf", "Paulada", new Date());
        AlunoDTO alun12 = new AlunoDTO(10, "Loira", "Do Tchan", new Date());
        AlunoDTO alun13 = new AlunoDTO(11, "Canela Seca", "Da Silva", new Date());
        AlunoDTO alun14 = new AlunoDTO(12, "Soldado Josney", "Pinto", new Date());
        AlunoDTO alun15 = new AlunoDTO(13, "Luiz", "Inácio Lula da Silva", new Date());
        ListaAlunos.add(alun1); ListaAlunos.add(alun2); ListaAlunos.add(alun3); ListaAlunos.add(alun4);
        ListaAlunos.add(alun5); ListaAlunos.add(alun6); ListaAlunos.add(alun7); ListaAlunos.add(alun10);
        ListaAlunos.add(alun11); ListaAlunos.add(alun12); ListaAlunos.add(alun13); ListaAlunos.add(alun14);
        ListaAlunos.add(alun15);
        for (AlunoDTO aluno : ListaAlunos) {
            MockPersistencia.getInstanciaListaAlunos().add(aluno);
        }

        ArrayList<MatriculaAlunoDTO> ListaMatriculaAlunos = new ArrayList<>();
        MatriculaAlunoDTO matAluno1 = new MatriculaAlunoDTO(alun1, 1, "matricula1", new Date(), true);
        MatriculaAlunoDTO matAluno2 = new MatriculaAlunoDTO(alun2, 2, "matricula2", new Date(), true);
        MatriculaAlunoDTO matAluno3 = new MatriculaAlunoDTO(alun3, 3, "matricula3", new Date(), true);
        MatriculaAlunoDTO matAluno4 = new MatriculaAlunoDTO(alun4, 4, "matricula4", new Date(), true);
        MatriculaAlunoDTO matAluno5 = new MatriculaAlunoDTO(alun5, 5, "matricula5", new Date(), true);
        MatriculaAlunoDTO matAluno6 = new MatriculaAlunoDTO(alun6, 6, "matricula6", new Date(), true);
        MatriculaAlunoDTO matAluno7 = new MatriculaAlunoDTO(alun7, 7, "matricula7", new Date(), true);
        MatriculaAlunoDTO matAluno8 = new MatriculaAlunoDTO(alun10, 8, "matricula8", new Date(), true);
        MatriculaAlunoDTO matAluno9 = new MatriculaAlunoDTO(alun11, 9, "matricula9", new Date(), true);
        MatriculaAlunoDTO matAluno10 = new MatriculaAlunoDTO(alun12, 10, "matricula10", new Date(), true);
        MatriculaAlunoDTO matAluno11 = new MatriculaAlunoDTO(alun13, 11, "matricula11", new Date(), true);
        MatriculaAlunoDTO matAluno12 = new MatriculaAlunoDTO(alun14, 12, "matricula12", new Date(), true);
        MatriculaAlunoDTO matAluno13 = new MatriculaAlunoDTO(alun15, 13, "matricula13", new Date(), true);
        ListaMatriculaAlunos.add(matAluno1); ListaMatriculaAlunos.add(matAluno2); ListaMatriculaAlunos.add(matAluno3);
        ListaMatriculaAlunos.add(matAluno4); ListaMatriculaAlunos.add(matAluno5); ListaMatriculaAlunos.add(matAluno6);
        ListaMatriculaAlunos.add(matAluno7); ListaMatriculaAlunos.add(matAluno8); ListaMatriculaAlunos.add(matAluno9);
        ListaMatriculaAlunos.add(matAluno10); ListaMatriculaAlunos.add(matAluno11); ListaMatriculaAlunos.add(matAluno12);
        ListaMatriculaAlunos.add(matAluno13);
        for (MatriculaAlunoDTO matAluno : ListaMatriculaAlunos) {
            MockPersistencia.getInstanciaListaMatriculaAlunos().add(matAluno);
        }

        TurmaDTO turma1 = new TurmaDTO();
        turma1.setId(1);
        turma1.setNomeMateria("Matemática");
        turma1.setProfessor(matProf1);
        turma1.getAlunos().add(matAluno3);
        turma1.getAlunos().add(matAluno9);
        turma1.getAlunos().add(matAluno4);
        TurmaDTO turma2 = new TurmaDTO(2, "Português", matProf6);
        MockPersistencia.getInstanciaListaTurmas().add(turma1); MockPersistencia.getInstanciaListaTurmas().add(turma2);
    }
}
